package com.lemon.cloud.websocket.handler;

import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.handler.TextWebSocketHandler;

@Slf4j
@AllArgsConstructor
@NoArgsConstructor
public class CustomWebSocketHandler extends TextWebSocketHandler {

    private PlanTextMessageHandler planTextMessageHandler;

    @Override
    public void handleTextMessage(WebSocketSession session, TextMessage message) throws JsonProcessingException {
        if (message.getPayloadLength() != 0) {
            log.info("message:{}",message.getPayload());
            this.planTextMessageHandler.handle(session, (String)message.getPayload());
        }
    }

}
